<template>
  <div class="serach-result">
    <van-nav-bar
    :title="$route.query.keyword + '的搜索结果'"
    fixed
    left-arrow
    @click-left="$router.back()"></van-nav-bar>
    <van-list
      :finished="finished"
      v-model="loading"
      @load="onLoad"
    >
      <van-cell
      v-for="(item, idx) in list"
      :key="idx"
      :title="item.title"
       @click="$router.push('/article/'+item.art_id.toString())"/>
    </van-list>
    <!-- <van-pagination
    v-model="page"
    :total-items="5"
    :items-per-page="15" /> -->
  </div>
</template>

<script>
import { getSearch } from '@/api/search'
export default {
  name: 'result',
  data () {
    return {
      loading: false,
      finished: false,
      list: [],
      page: 1
    }
  },
  created () {

  },
  methods: {
    async onLoad () {
      // 异步更新数据
      const keyword = this.$route.query.keyword
      const res = await getSearch(keyword, this.page)
      const results = res.data.data.results
      // 加载状态结束
      this.list.push(...results)
      this.page++
      this.loading = false
      // 数据全部加载完成
      if (this.list.length >= 40) {
        this.finished = true;
      }
    }
  }
}
</script>

<style lang='less' scoped>
.serach-result {
  height: 100%;
  overflow: auto;
  .van-list {
    margin-top: 39px;
  }
}
</style>
